package com.topvision.gsj.launcher;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.topvision.gsj.launcher.domain.AppInfo;
import com.topvision.gsj.library.TouchInterface;
import com.topvision.gsj.library.util.ImageLoaderUtil;

public class AppFragment extends Fragment {
	public static final String APP_INFO = "app_info";
	public static final String APPFRAGMENT_LOG = "APPFRAGMENT_LOG";

	public AppFragment() {

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.app_item, container, false);

		ImageView appIcon = (ImageView) view.findViewById(R.id.app_icon);
		TextView appName = (TextView) view.findViewById(R.id.app_name);
		Bundle bundle = getArguments();
		final AppInfo appInfo = (AppInfo) bundle.getParcelable(APP_INFO);
		appName.setText(appInfo.getAppName());

		appIcon.setImageDrawable(appInfo.getAppIcon());
		// final LinearLayout appLinear = (LinearLayout) view
		// .findViewById(R.id.app_linear);
		// appLinear.setOnClickListener(new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		//
		// ComponentName componentName = new ComponentName(appInfo
		// .getPackageName(), appInfo.getClassName());
		// Intent intent = new Intent();
		// intent.setComponent(componentName);
		// startActivity(intent);
		// }
		// });
		return view;
	}

	public static Fragment newInstance(AppInfo appInfo) {
		AppFragment fragment = new AppFragment();
		Bundle bundle = new Bundle();
		bundle.putParcelable(APP_INFO, appInfo);
		fragment.setArguments(bundle);
		return fragment;
	}

}
